#Author: Mike Schladt - 2014
#module to return the compile time of a PE file

import time
import pefile
from lib.cuckoo.common.abstracts import Processing
from lib.cuckoo.common.exceptions import CuckooProcessingError

class CompileTime(Processing):

    def get_compile_time(self):
        pe = pefile.PE(self.file_path)
        epoch = pe.FILE_HEADER.TimeDateStamp
        humantime = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(epoch))
        return humantime

    def run(self):
        self.key = 'compiletime'
    
        try:
            data = self.get_compile_time()
        except Exception as e:
            raise CuckooProcessingError("Unable to find compile time"
                                        ": {0}".format(e))
        
        return data


